import React, { useEffect } from "react";
import { useLocation, useNavigate } from "react-router-dom";

const WidthRouter = (Cpn: any) => {
  const Width = () => {
    let { pathname } = useLocation();
    const navigate = useNavigate();
    let token = localStorage.getItem("token");
    useEffect(() => {
      if (!token && !["/login", "/home/home", "/sigin"].includes(pathname)) {
        navigate("/login");
      }
    }, [pathname]);
    return <Cpn />;
  };
  return Width;
};
export default WidthRouter;
